//
//  COSConfigurationProvider.swift
//  Center_OSS
//
//  Created by 蒋晨成 on 2022/2/10.
//

import Foundation

public enum COSConfigurationProvider {}

extension COSConfigurationProvider {
    private(set) static var configuration: COSUploadConfiguration?
}

extension COSConfigurationProvider {
    static func asyncGetConfiguration(byType type: BusinessType = .image, complete: @escaping (Result<Void, Error>) -> Void) {
        if configuration != nil {
            complete(.success(()))
            return
        }

        TencentCOSCenter.context?.getUploadToken(type: type.rawValue) { result in
            switch result {
            case .success(let configuration):
                self.configuration = configuration
                complete(.success)
            case .failure(let error):
                complete(.failure(error))
            }
        }
    }
}
